package com.itheima.customer.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.customer.dao.IBaseDictDao;
import com.itheima.customer.dao.ICustomerDao;
import com.itheima.customer.domain.BaseDict;
import com.itheima.customer.domain.Customer;
import com.itheima.customer.service.ICustomerService;

/**
 * 客户的业务层实现类
 * @author Administrator
 *
 */
@Service("customerService")
@Transactional(readOnly=true,propagation=Propagation.SUPPORTS)
public class CustomerServiceImpl implements ICustomerService {

	@Autowired
	private ICustomerDao customerDao;
	
	@Autowired
	private IBaseDictDao basedictDao;
	
	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void addCustomer(Customer customer) {
		customerDao.save(customer);
	}

	@Override
	public List<Customer> findAllCustomer(DetachedCriteria dCriteria) {
		return customerDao.findAll(dCriteria);
	}

	@Override
	public Customer findCustomer(Customer customer) {
		
		return (Customer) customerDao.findCustomer(customer);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void update(Customer customer) {
		customerDao.update(customer);
		
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void delete(Customer customer) {
		customerDao.delete(customer);
		
	}

	@Override
	public List<BaseDict> findCustSources() {
		
		return basedictDao.findBaseDictByTypeCode("002");
	}

	@Override
	public List<BaseDict> findCustLevels() {
		
		return basedictDao.findBaseDictByTypeCode("006");
	}

	@Override
	public BaseDict findBaseDictById(String dictId) {
		
		return basedictDao.findById(dictId);
	}

	@Override
	public List<Customer> findAllCustomers() {
		return customerDao.findAllCustomers();
	}

	@Override
	public Customer findCustomerById(Long custId) {
		return (Customer) customerDao.findCustomerById(custId);
	}

}
